//
//  Cep.m
//  YouthOlympic2014
//
//  Created by Li Yuhang on 14-7-1.
//  Copyright (c) 2014年 mitian. All rights reserved.
//

#import "Cep.h"
#import "CepEvent.h"
@interface Cep()
@property (nonatomic, copy) NSString* iconTag;
@property (nonatomic, copy) NSString* picTag;
@property (nonatomic, strong) NSArray* picsTag;
@end

@implementation Cep
@synthesize id,title,content,iconTag,picTag,picsTag,index,events,place;

- (UIImage*) icon{
    NSDictionary* iconDict = @{
                               @"1": @"cep-cun@2x.png",
                               @"2": @"cep-media@2x.png",
                               @"3": @"cep-shine@2x.png",
                               @"5": @"cep-chumo@2x.png",
                               @"6": @"cep-qingnian@2x.png"};
    
    return [UIImage imageNamed:iconDict[self.id]];
}

- (NSString*) iconPath{
    NSDictionary* iconDict = @{
                               @"1": @"img/cep-cun@2x.png",
                               @"2": @"img/cep-media@2x.png",
                               @"3": @"img/cep-shine@2x.png",
                               @"5": @"img/cep-chumo@2x.png",
                               @"6": @"img/cep-qingnian@2x.png"};
    
    return iconDict[self.id];
}

- (UIImage*) image{
    return [UIImage imageNamed:@"cep1.jpg"];
}

- (UIImage*) detailImages{
    NSMutableArray* pics = nil;
    return nil;
}

- (NSArray*) detailImagePaths{
    return nil;
}

- (NSString*) displaytime{
    return @"";
}


+(NSArray*/*Cep*/) instanceList: (NSDictionary*) jsonData{
    NSArray *jsonCeps = (NSArray*)jsonData[@"AllCepInfo"];
    NSMutableArray* /*Cep*/ ceps = [[NSMutableArray alloc]init];
    //
    for(int i=0; i< jsonCeps.count ; i++){
        Cep* cep = [[Cep alloc]init];
        NSDictionary* cepJson = jsonCeps[i];
        cep.id = cepJson[@"cepid"];
        cep.title = cepJson[@"ceptitle"];
        cep.content = cepJson[@"cepcontent"];
        cep.place = cepJson[@"cepplace"];
        [ceps addObject:cep];
    }
    
    return [NSArray arrayWithArray:ceps];
}

+(Cep* ) instance:(NSDictionary*) jsonData{
    Cep* cep = [[Cep alloc] init];
    
    NSDictionary* obj =  jsonData[@"TheOneCepInfo"];
    cep.id = obj[@"cepid"];
    cep.title = obj[@"ceptitle"];
    cep.content = obj[@"cepcontent"];
    cep.place = obj[@"cepplace"];
    
    NSMutableArray* events = [[NSMutableArray alloc] init];
    NSArray* eventsJsonData = (NSArray*)obj[@"event"];
    
    for(int i =0; i< eventsJsonData.count; i++){
        CepEvent* event = [[CepEvent alloc]init];
        NSDictionary* eventJsonData = eventsJsonData[i];
        //
        event.id = eventJsonData[@"eventid"];
        event.begintime = eventJsonData[@"begintime"];
        event.endtime = eventJsonData[@"endtime"];
        //
        [events addObject: event];
        
    }
    cep.events = [NSArray arrayWithArray:events];
    //
    return cep;
}


-(NSString *)description{
    return [NSString stringWithFormat: @"{cepid:%@, ceptitle:%@, cepcontent:%@, cepplace:%@}", self.id, self.title, self.content, self.place];
}


@end
